/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-08-15 11:50:07
 * @LastEditors: TT
 * @LastEditTime: 2023-10-31 16:06:22
 */

import 'package:flutter/material.dart';
import 'package:hzy_project_template/base_ui_config/base_ui_config_index.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/controllers/user_c.dart';
import 'package:hzy_project_template/pages/login/vm/login_vm.dart';

import 'package:hzy_project_template/utils/utils_index.dart';

import '../widgets/login_child_widget.dart';
import '../config/note_login_config.dart';

class NoteLoggedInV extends CommonGetXV<NoteLoggedInC> {
  NoteLoggedInV({Key? key}) : super(key: key);
  @override
  NoteLoggedInC get controller => Get.put(NoteLoggedInC());

  @override
  Widget createBody({
    required BuildContext context,
    BoxConstraints? constraints,
  }) {
    Widget body = LoginChildWidget(
      config: controller.noteLoginConfig,
      tapCallback: (imageModel) {
        controller.tapDo();
      },
    );
    return body;
  }
}

class NoteLoggedInC extends CommonGetXController {
  // --------- 属性 --------- //

  NoteLoginConfig noteLoginConfig = NoteLoginConfig();
  LoginVM vm = LoginVM();
  // --------- 生命周期  --------- //
  @override
  configDefault() {
    configNormalData();
    isShowAppBar = false;
    safeAreatop = false;
    scallBackGroundColor = HzyCommonColor().whitebackgroundColor;
    safeAreabottm = true;
  }

  // --------- 数据处理  --------- //

  /// 配置默认数据

  configNormalData() async {
    var userModel = getUserInfo();
    if (userModel != null) {
      noteLoginConfig.imageNormalModel = UserC.current.loaclImageModle;
      noteLoginConfig.nickName = userModel.nickName;
      noteLoginConfig.account = userModel.account;
    }
  }
  // --------- 触发事件  --------- //

  tapDo() async {
    await vm.configLogin(
      account: noteLoginConfig.nickName!,
      pwd: noteLoginConfig.passWordInputModel.text!,
    );
  }
}
